/**
 * 财务工资小计部门维护
 */

app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
	var gridId = $scope.gridId;
	
	$scope.bindBtn = function(event) {
		switch(event){
		case 'event-to-add': // 新增
		{
			var listUkey = [];
			for(var i=0;i<$scope.subGrid.sonlist.length;i++){
				var data = $scope.subGrid.sonlist[i];
				listUkey.push(data.orgid);
			}
			$scope.showModalCheckBox('TS_OrganizationInfo_ByFinanceSalary', 'orgid', listUkey);
			break;
		}
		case 'event-to-delete': // 删除
		{
			$scope.subGrid.deleteBatch();
			break;
		}
	};
	}
}



/*
 * 子列表控制器
 */
app.controller('subGridCtrl', ['$scope', '$http', function SubGridController($scope, $http){
	/*
	 * 复选框回调
	 */
	$scope.checkbox.afterSelectDatas = function(rowsSelected) {

		for (var i = 0; i < rowsSelected.length; i++) {
			var row = rowsSelected[i];
			var isAdd = true; // 根据现有存在，是否加新行
			for (var j = 0; j < $scope.subGrid.sonlist.length; j++) {
				if ($scope.subGrid.sonlist[j].orgid == row.orgid) {
					isAdd = false;
				}
			}
			if (isAdd) {
				$scope.subGrid.sonlist.push({
					id: "",
					orgid: row.orgid,
					orgName: row.orgNameNew,
					orgNameNew: row.orgNameNew
				});
			}
		}

	}
}]);
